import { ajax } from "@/utils/ajax";

// 小组类型定义
export interface Group {
    id: number;
    name: string;
    bornTime: string; 
    profile: string;
    hot: number;
    number: number; 
    createTime: string; 
    teacherName?: string[]; 
}

// 学生类型定义
export interface Student {
    id: number;
    studentNumber?: string;
    name: string;
    age: number;
    sex: number;

}

// 教师类型定义
export interface Teacher {
    id: number;
    name: string;
    position: string;

}

// 事件日志接口
export interface EventLog {
    id: number;
    groupId: number;
    studentId: number;
    studentName: string;
    logType: number; // 1:加入小组, 2:退出小组
    createTime: string;
    log?: string;
}

// 新增小组
export interface GroupForAdd {
    name: string;
    bornTime: string;
    profile: string;
}

// 编辑小组
export interface GroupForEdit {
    id: number;
    name: string;
    bornTime: string;
    profile: string;
    hot: number;
    createTime: string;
}

// 获取小组列表
export const getGroupList = (params: {
    pageNum?: number;
    pageSize?: number;
}, options?: RequestInit) => {
    return ajax.get("/group/getList", {
        params,
        ...options
    });
};

// 根据ID获取小组
export const getGroupById = (id: number, options?: RequestInit) => {
    return ajax.get("/group/get", {
        params: { id },
        ...options
    });
};

// 添加小组
export const addGroup = (data: GroupForAdd) => {
    return ajax.post("/group/add", data);
};

// 编辑小组
export const editGroup = (data: GroupForEdit) => {
    return ajax.post("/group/edit", data);
};

// 删除小组
export const deleteGroup = (id: number) => {
    return ajax.delete("/group/delete", {
        params: { id }
    });
};

// 获取小组的所有学生
export const getGroupStudents = (id: number, pageNum?: number, pageSize?: number) => {
    return ajax.get("/group/getStudent", {
        params: {
            id,
            pageNum,
            pageSize
        }
    });
};

// 获取小组的所有教师
export const getGroupTeachers = (id: number, pageNum?: number, pageSize?: number) => {
    return ajax.get("/group/getTeacher", {
        params: {
            id,
            pageNum,
            pageSize
        }
    });
};

export const searchGroups = (data: { name?: string }, params: { pageNum?: number, pageSize?: number }, options?: RequestInit) => {
    return ajax.post("/group/Search", data, {
        params,
        ...options
    });
};

// 获取小组事件记录
export const getGroupEvents = (id: number) => {
    return ajax.get<EventLog[]>("/group/getLog", {
        params: { id }
    });
};